/*
 * User Router
 * @Author: chiangbt@geoportal.cn 
 * @Date: 2019-05-09 10:22:14 
 * @Last Modified by:   chiangbt@geoportal.cn 
 * @Last Modified time: 2019-05-09 10:22:14 
 */
const express = require("express");
const router = express.Router();

const jwt = require('express-jwt');
const userController = require('../controllers/userController');

/**
 * 注册用户
 */
router.post("/auth/signup", userController.user_singup);

/**
 * 用户登录
 * 返回用户token
 */
router.post("/auth/login", userController.user_login);

/**
 * 用户重置密码
 */
router.post("/auth/resetpassword", userController.user_resetpassword);

/**
 * 用户验证
 * 验证header中的authorization是否正确
 */
router.get("/auth/profile", jwt({
    secret: process.env.SecretOrPublicKey
}), userController.user_profile);

/**
 * 获取指定用户
 */
router.get("/auth/user/:id", jwt({
    secret: process.env.SecretOrPublicKey
}), userController.user_get_by_id);

/**
 * 删除用户
 */
router.delete("/auth/user/:id", jwt({
    secret: process.env.SecretOrPublicKey
}), userController.user_delete);


/**
 * 获取用户
 */
router.get("/auth/user", jwt({
    secret: process.env.SecretOrPublicKey
}), userController.user_get_all);


/**
 * 更新用户角色和是否活跃
 */
router.patch("/auth/user/:id", jwt({
    secret: process.env.SecretOrPublicKey
}), userController.user_update);

module.exports = router;